﻿using LogisticsTrackingWebApi_V3.Models;
using LogisticsTrackingWebApi_V3.Services;

namespace LogisticsTrackingWebApi_V3.ServicesImpl.Providers
{

    /// <summary>
    /// 顺丰物流查询实现
    /// </summary>
    public class SFExpressProvider : ILogisticsProvider
    {
        public string CompanyCode => "SF";
        public string CompanyName => "顺丰速运";

        public async Task<LogisticsInfo> QueryTrackingAsync(string trackingNumber)
        {
            // 模拟调用顺丰API查询
            await Task.Delay(100); // 模拟网络请求延迟

            // 模拟返回结果
            return new LogisticsInfo
            {
                TrackingNumber = trackingNumber,
                CompanyCode = CompanyCode,
                CompanyName = CompanyName,
                Status = "运输中",
                Traces = new List<LogisticsTrace>
            {
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddHours(-24),
                    Location = "深圳市",
                    Description = "快递已发出"
                },
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddHours(-12),
                    Location = "广州市",
                    Description = "快递已到达中转中心"
                },
                new LogisticsTrace
                {
                    Time = DateTime.Now.AddHours(-2),
                    Location = "上海市",
                    Description = "快递正在派送中"
                }
            }
            };
        }

        public bool MatchTrackingNumber(string trackingNumber)
        {
            // 顺丰运单号规则：12位或13位数字，通常以106或2开头
            return !string.IsNullOrEmpty(trackingNumber) &&
                   (trackingNumber.Length == 12 || trackingNumber.Length == 13) &&
                   long.TryParse(trackingNumber, out _) &&
                   (trackingNumber.StartsWith("106") || trackingNumber.StartsWith("2"));
        }
    }

}
